package cn.lizemin.demo.thread;

/**
 * @author: lizemin
 * @version: 1.0
 */
public class Ticket implements Runnable{
    int ticket_num = 100;
    Object object = new Object();
    @Override
    public void run() {
        while (true){//卖票窗口永远开启
            synchronized (object){
                if (ticket_num > 0){
                    //模拟出票时间
                    try {
                        Thread.sleep(50);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                    String name = Thread.currentThread().getName();
                    System.out.println(name+"正在卖第"+ticket_num--+"张票");

                }
            }


        }

    }
}
